package com.wgh.api.client.fallback;

import com.wgh.api.client.pay.PayClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付服务客户端熔断降级实现
 */
@Component
public class PayClientFallback implements PayClient {

    private static final Logger log = LoggerFactory.getLogger(PayClientFallback.class);

    @Override
    public Map<String, Object> createPayOrder(Map<String, Object> params) {
        log.error("支付服务调用失败，降级处理：createPayOrder(params={})", params);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 500);
        result.put("message", "支付服务暂时不可用，请稍后再试");
        return result;
    }

    @Override
    public Map<String, Object> queryPayOrderStatus(Long orderId) {
        log.error("支付服务调用失败，降级处理：queryPayOrderStatus(orderId={})", orderId);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 500);
        result.put("message", "查询支付状态失败");
        return result;
    }

    @Override
    public String payNotify(Integer payType, Map<String, String> notifyData, Map<String, String> queryParams) {
        log.error("支付服务调用失败，降级处理：payNotify(payType={}, notifyData={}, queryParams={})", 
                 payType, notifyData, queryParams);
        return "FAIL";
    }

    @Override
    public Map<String, Object> closePayOrder(Long orderId) {
        log.error("支付服务调用失败，降级处理：closePayOrder(orderId={})", orderId);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 500);
        result.put("message", "关闭支付订单失败");
        result.put("success", false);
        return result;
    }

    @Override
    public Map<String, Object> refund(Map<String, Object> params) {
        log.error("支付服务调用失败，降级处理：refund(params={})", params);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 500);
        result.put("message", "退款处理失败");
        result.put("success", false);
        return result;
    }

    @Override
    public Map<String, Object> queryRefundStatus(Long orderId) {
        log.error("支付服务调用失败，降级处理：queryRefundStatus(orderId={})", orderId);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 500);
        result.put("message", "查询退款状态失败");
        return result;
    }

    @Override
    public Map<String, Object> getPayChannelConfig(Integer payType) {
        log.error("支付服务调用失败，降级处理：getPayChannelConfig(payType={})", payType);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 500);
        result.put("message", "获取支付渠道配置失败");
        return result;
    }

    @Override
    public Map<String, Object> unifiedPay(Map<String, Object> payParams) {
        log.error("支付服务调用失败，降级处理：unifiedPay(payParams={})", payParams);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 500);
        result.put("message", "统一支付接口调用失败");
        return result;
    }
}